package cn.usian.service.impl;

import cn.usian.common.R;
import cn.usian.dao.CategoryDao;
import cn.usian.dao.DishDao;
import cn.usian.entity.Dish;
import cn.usian.entity.DishDto;
import cn.usian.service.DishService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class DishServiceImpl implements DishService {
    @Resource
    private DishDao dishDao;

    @Resource
    private CategoryDao categoryDao;



    @Override
    public R<Page<Dish>> page(Integer page, Integer pageSize, String name) {
        LambdaQueryWrapper<Dish> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.like(name!=null,Dish::getName,name);

        Page<Dish> dishPage = dishDao.selectPage(new Page<>(page, pageSize), queryWrapper);

        return R.success(dishPage);
    }

    @Override
    public void del(long[] ids) {
        for (long id : ids) {
            dishDao.deleteById(id);
        }
    }

    @Override
    public R status(Integer status, long[] ids) {
        Dish dish=new Dish();
        for (long id : ids) {
            dish.setId(id);
            dish.setStatus(status);
            dishDao.updateById(dish);
        }
        return R.success("修改成功");
    }



}
